<?php 

require_once 'BingAPI.php';

function fetchCompanyLogo($companyName) {

$query = $companyName."+logo";

#$query = urlencode($query);

// Simply start the class with your AppID argumented
$search = new BingAPI('068389FED6DC67A29FCC69601CECA2E778BDE18A');
/* To use multiple resources simply do 
   ->setSources('Web+Image') , 
   it must match the source type bing.com provides */
// Build your query easily
$search->query($query)
       ->setSources('image') 

       ->setFormat('json')
 # Also you can try: xml, soap or json
       ->setOptions(
          array(
                'Web.Count' => '1',  
                'Web.Offset' => '0', 
                'Adult' => 'Moderate', 
                'Options' => 'EnableHighlighting')
);

 # Check the API documentation in bing.com for more information

# This will give you a raw output

#print_r($search);
#echo $search->getResults();

#$response = file_get_contents($request); 
$jsonobj = json_decode($search->getResults()); 
foreach($jsonobj->SearchResponse->Image->Results as $value) { 
#$img = '/mnt/www/sapleads/images/'.$companyName;
#file_put_contents($img, file_get_contents($value->Thumbnail->Url));
	return $value->Thumbnail->Url;
} 

return "";
}

